package java课题设计.功能类.修改学生或者删除学生;
import java课题设计.工具类.Seek;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
 
public class StudentID extends JFrame implements MouseListener {
    Font f=new Font("宋体",Font.BOLD,25);
    String id;
    private JFrame pre;
    private JTable table;
    JButton seek=new JButton("查找");
    public StudentID() {
        extracted();
        initImage();
        this.setVisible(true);
    }
 
    public void initImage(){
        //添加输入学号提示框
        JLabel ID=new JLabel("请输入你要查找的学号");
        ID.setFont(f);
        ID.setBounds(75,40,400,100);
        this.getContentPane().add(ID);
 
 
        //输入学号输入文本框
        JTextField IDtext=new JTextField();
        IDtext.setBounds(75,140,250,50);
        this.getContentPane().add(IDtext);
        //添加监听器
        IDtext.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                id = IDtext.getText();
            }
 
            @Override
            public void removeUpdate(DocumentEvent e) {
                id = IDtext.getText();
            }
 
            @Override
            public void changedUpdate(DocumentEvent e) {
                id = IDtext.getText();
            }
        });
 
        //添加查找按钮
        seek.setFont(f);
        seek.setBounds(100,220,140,45);
        this.getContentPane().add(seek);
 
    }
 
    public void extracted(){
        //设置登录界面的长和宽
        this.setSize(500,450);
        this.setTitle("请输入你要修改的学生的学号");
        this.setAlwaysOnTop(true);
        this.setDefaultCloseOperation(3);
        this.setLayout(null);
        this.setLocationRelativeTo(null);
 
        //绑定监听器
        seek.addMouseListener(this);
    }
    public void chazhao(String id) throws IOException {
        boolean flag= Seek.seek3(id);
        if(flag==false){
            //说明找到了这个学号的学生
            new Revise();
            this.setVisible(false);
        }
        else {
            //跳出弹窗查找失败
            System.out.println("查找失败");
            JDialog wrong=new JDialog(this,null,true);
            wrong.setBounds(550,300,300,200);
            wrong.setTitle("未找到该学生");
            JLabel w=new JLabel("未找到该学生");
            w.setFont(new Font("宋体",Font.BOLD,18));
            w.setBounds(100,100,100,100);
            wrong.add(w);
            wrong.setAlwaysOnTop(true);
            wrong.setVisible(true);
        }
 
    }
 
    @Override
    public void mouseClicked(MouseEvent e) {
        if(e.getSource()==seek){
            System.out.println("点击了查找按钮");
            try {
                chazhao(id);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
 
    @Override
    public void mousePressed(MouseEvent e) {
 
    }
 
    @Override
    public void mouseReleased(MouseEvent e) {
 
    }
 
    @Override
    public void mouseEntered(MouseEvent e) {
 
    }
 
    @Override
    public void mouseExited(MouseEvent e) {
 
    }
}
